package leetcode.bitarithmetic;

public class BinaryNumberWithAlternatingBits639 {
    class Solution1 {
        public boolean hasAlternatingBits(int n) {
            int ans = 0;
            for (int i = 0; i < 32 && n != 0; i++) {
                int cur = 1 & n;
                n >>= 1;
                if ((cur ^ (n & 1)) == 0) {
                    return false;
                }
            }
            return true;
        }
    }

    class Solution2 {
        public boolean hasAlternatingBits(int n) {
            while(n > 0){
                if(n % 2 == (n / 2) % 2) {
                    return false;
                }
                n /= 2;
            }
            return true;
        }
    }

    class Solution3 {
        public boolean hasAlternatingBits(int n) {
            while (n != 0) {
                if ((n % 2) == (n / 2 % 2)) {
                    return false;
                }
                n /= 2;
            }
            return true;
        }
    }
}
